import store from "../../../store";
const color10 = [
  "#1890ff",
  "#38b05c",
  "#1699b7",
  "#F6BD16",
  "#dc6a1f",
  "#6F5EF9",
  "#1E9493",
  "#bbe800",
  "#76523b",
  "#5D7092",
];
const common = {
  // theme color etc
  theme: {
    lightBlue: "#004e92",
    deepBlue: "#000428",
    primaryColor: "#1890ff",
    primaryOrange: "#dc6a1f",
    primaryRed: "#ff4500",
    primaryGreen: "#1699b7",
    primaryYellow: "#f6bd16",
    lightGreen: "#38b05c",
    textGreen: "#17a3ac",
    lightWhite: "rgba(255, 255, 255, 0.65)",
  },
  themeColor10: color10,
  chartTheme: {
    defaultColor: "#38b05c",
    colors10: color10,
    components: {
      axis: {
        common: {
          label: {
            style: {
              fill: "rgba(255,255,255,0.65)",
              fontSize: 12,
            },
          },
          grid: {
            line: {
              style: {
                lineDash: [5],
                stroke: "rgba(255,255,255,0.2)",
              },
            },
          },
        },
      },
      legend: {
        common: {
          itemName: {
            style: {
              fill: "rgba(255,255,255,0.6)",
            },
          },
        },
      },
      tooltip: {
        showCrosshairs: true,
        shared: true,
      },
    },
  },
  chartLabelStyle: {
    label: {
      style: {
        fill: "rgba(255,255,255,0.65)",
      },
    },
  },
  chartGridLine: {
    grid: {
      line: {
        style: {
          lineDash: [5],
          stroke: "rgba(255,255,255,0.2)",
        },
      },
    },
  },
  scrollBoardStyle: {
    oddRowBGC: "rgba(255,255,255,0.1)",
    evenRowBGC: "rgba(0,0,0,0.1)",
  },
  countToInit: {
    oldVal: 0,
    newVal: 0,
  },
  // 加载地图
  loadTMap: () => {
    return new Promise((resolve, reject) => {
      // XY3BZ-3IKCP-2WADY-VABVN-QYDNO-BRBDL

      const { map } = store.getters.returnConfig;
      if (map && map.qq_map_key) {
        let script = document.createElement("script");
        script.type = "text/javascript";
        script.src = `https://map.qq.com/api/gljs??v=1.exp&key=${map.qq_map_key}&callback=initMap`;
        document.getElementsByTagName("head")[0].appendChild(script);
        resolve();
      } else {
        reject();
      }
    });
  },
  // 适配不同屏幕页面字体大小
  setPageFontSize: () => {
    const width = document.documentElement.clientWidth;
    const html = document.getElementsByTagName("html")[0];
    /**
    1280 * 720 ： 笔记本
    1366 * 768 ： 普通液晶显示器
    1920 * 1080： 高清液晶显示器
    2560 * 1440： 2K高清显示器
    4096 * 2160： 4K高清显示器
   * 
   * */
    // 设置rem基础font-size (页面文字1.4rem)
    if (width <= 1280) {
      html.style.fontSize = "53.6%"; //  (12px)
    } else if (width <= 1920) {
      html.style.fontSize = "62.5%"; // 10px(14px)
    } else if (width <= 2560) {
      html.style.fontSize = "71.43"; // 12px(16px)
    } else {
      html.style.fontSize = "80.36%"; // 14px(18px)
    }
  },
  // 寻找数组最大最小值
  findMaxMin: (data, valueKey) => {
    let maxValue = 0;
    let minValue = 5000000000;
    let maxObj = null;
    let minObj = null;
    for (const d of data) {
      if (d[valueKey] > maxValue) {
        maxValue = d[valueKey];
        maxObj = d;
      }
      if (d[valueKey] < minValue) {
        minValue = d[valueKey];
        minObj = d;
      }
    }
    return { max: maxObj, min: minObj };
  },
};

export default common;
